/**
 * 〈〉
 *
 * @author 王青杰
 * @create 2018-08-0810:19
 * @since 1.0.0
 */
package org.wlgzs.website.wlgzsoffice.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.wlgzs.website.wlgzsoffice.dao.AttendanceDao;
import org.wlgzs.website.wlgzsoffice.entity.TbAttendance;
import org.wlgzs.website.wlgzsoffice.enums.ResultEnum;
import org.wlgzs.website.wlgzsoffice.service.AttendanceService;
import org.wlgzs.website.wlgzsoffice.util.ResultMsg;

import javax.annotation.Resource;
import java.util.*;
@Service
public class AttendanceServiceImpl  implements AttendanceService{
    @Resource
    AttendanceDao attendanceDao;

    @Override
    public ResultMsg insert(TbAttendance attendance) {
        if(attendance!=null){
            attendanceDao.insert(attendance);
            return new ResultMsg(ResultEnum.SAVE,attendance);
        }
        return new ResultMsg(ResultEnum.UNSAVE,attendance);
    }

    @Override
    public ResultMsg delete(int attendanceId) {
        if(attendanceDao.selectByPrimaryKey(attendanceId)!=null){
            attendanceDao.deleteByPrimaryKey(attendanceId);
            PageHelper.startPage(0.10);
            List<TbAttendance> attendanceList = attendanceDao.checkAll();
            PageInfo pageInfo = new PageInfo(attendanceList);
            return new ResultMsg(ResultEnum.DELETE,pageInfo);
        }
        PageHelper.startPage(0.10);
        List<TbAttendance> attendanceList = attendanceDao.checkAll();
        PageInfo pageInfo = new PageInfo(attendanceList);
        return new ResultMsg(ResultEnum.UNDELETE,pageInfo);
    }

    @Override
    public ResultMsg update(TbAttendance attendance) {
        if(attendanceDao.selectByPrimaryKey(attendance.getAttendanceId())!=null){
            attendanceDao.updateByPrimaryKey(attendance);
            return new ResultMsg(ResultEnum.UPDATE,attendance);
        }
        return new ResultMsg(ResultEnum.UNUPDATE,attendance);
    }

    @Override
    public ResultMsg checkAll(int pageNum, TbAttendance attendance) {
        PageHelper.startPage(pageNum,10);
        List<TbAttendance> attendanceList = attendanceDao.checkAll();
        PageInfo<TbAttendance> pageInfo = new PageInfo<>(attendanceList);
        return new ResultMsg(ResultEnum.QUIRY,pageInfo);
    }
}
